//
//  HZTabBar.m
//  微博 OC
//
//  Created by 黑眼圈 on 16/4/18.
//  Copyright © 2016年 heiyan. All rights reserved.
//

#import "HZTabBar.h"
#import "UIView+JACKFrameExt.h"

@interface HZTabBar()

@property(nonatomic,weak)UIButton*  btn;

@end

@implementation HZTabBar


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        
        [self setupUI];
        
    }
    return self;
}


-(void)setupUI{
    
    
    UIButton* btn = [[UIButton alloc]init];
    
    self.btn = btn;
    
    //添加按钮点击事件
    [btn addTarget:self action:@selector(addMessage) forControlEvents:UIControlEventTouchUpInside];
    
      [btn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
    [btn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateHighlighted];
    
    [btn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateHighlighted];
      [btn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
    
    //让按钮和里面内容一样大小
    [btn sizeToFit];
    
    [self addSubview:btn];
}

#pragma mark -
#pragma mark     按钮点击事件
-(void)addMessage{
    
//    NSLog(@"ffeff");
    //block回调
    self.addBlock();
}


//布局
-(void)layoutSubviews{
    [super layoutSubviews];
    
    self.btn.center = CGPointMake(self.frame.size.width/2, self.frame.size.height/2);
    
    CGFloat w = self.frame.size.width/5;
    
    NSInteger inde = 0;
    
    for (id btn in self.subviews) {
        
        Class cla = NSClassFromString(@"UITabBarButton");
        
        if ([btn isKindOfClass:cla]) {
        
            UIButton* b = (UIButton*)btn;
            
            b.w = w;
            b.x = inde*w;
            
            if (inde==1) {
                inde++;
            }
            
            inde++;
        }
    }
    
}





















@end
